package com.wutao.panzh.index.content.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import com.panzh.UtilEntity.ResultVO;
import com.panzh.entity.FoodClassification;
import com.panzh.entity.FoodItem;
import com.panzh.entity.SceneryClassification;
import com.panzh.entity.SceneryItem;
import com.panzh.entity.index.IndexFoodItem;
import com.panzh.entity.index.IndexSceneryItem;
import com.panzh.myconst.CommonConst;
import com.wutao.panzh.service.FoodClassificationService;
import com.wutao.panzh.service.FoodItemService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 2020年1月16日
 * author：吴涛涛
 * 此模块为前端页面展示indexSpecialFood，特色美食的模块
 */
@Controller
public class IndexSpecialFoodHandler {

    @Reference
    private FoodItemService foodItemService;

    @Reference
    private FoodClassificationService foodClassificationService;


    @ResponseBody
    @RequestMapping("/get/food/classification")
    public ResultVO getSceneryClassification(){
        List<FoodClassification> allClassIfication = null;
        try {
            allClassIfication = foodClassificationService.getAllClassIfication();
        } catch (Exception e) {
            return new ResultVO<String>(ResultVO.FAILED, CommonConst.GET_INFORMATION_FAILED,ResultVO.NO_DATA );
        }
        return new ResultVO<List<FoodClassification>>(ResultVO.SUCCESS, ResultVO.NO_MSG,allClassIfication);
    }

    /**
     * 咱们默认还是要使用一个分页的东东的。classificationId是分类的id，更加方便我们进行属性的筛选；
     * @return
     */
    @ResponseBody
    @RequestMapping("/get/all/index/foodItem")
    public ResultVO getAllIndexFoodItem(@RequestParam(value="pageNo",defaultValue="1") Integer pageNo,
                                           @RequestParam(value = "classificationId",required = false,defaultValue = "0") Integer classificationId){
        PageInfo<IndexFoodItem> indexFoodItemPageInfo = foodItemService.getAllIndexFoodItem(pageNo,classificationId);
        return new ResultVO<PageInfo<IndexFoodItem>>(ResultVO.SUCCESS,ResultVO.NO_MSG ,indexFoodItemPageInfo);
    }

    //    href='show_scenery_details?itemId=" + itemId + "'
    @RequestMapping("show_food_details")
    public String getShowIndexFoodDetails(@RequestParam("itemId") Integer itemId, Model model){
        //转来转去，我是真的吧自己弄烦了。
        FoodItem foodItem = foodItemService.getFoodItemById(String.valueOf(itemId));
        model.addAttribute("foodItem",foodItem);
        return "FoodDetails";
    }

}
